package com.ruoyi.archives.service.impl;

import java.util.LinkedList;
import java.util.List;

import com.ruoyi.archives.utile.DirectorRoleUtile;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.UuidUtils;
import com.ruoyi.system.mapper.SysDeptMapper;
import com.ruoyi.system.mapper.SysRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.archives.mapper.SysRelativesMapper;
import com.ruoyi.archives.domain.SysRelatives;
import com.ruoyi.archives.service.ISysRelativesService;

/**
 * 家庭成员情况Service业务层处理
 * 
 * @author gzhankh
 * @date 2022-02-27
 */
@Service
public class SysRelativesServiceImpl implements ISysRelativesService 
{
    @Autowired
    private SysRelativesMapper sysRelativesMapper;

    @Autowired
    private DirectorRoleUtile directorRoleUtile;

    /**
     * 查询家庭成员情况
     * 
     * @param id 家庭成员情况主键
     * @return 家庭成员情况
     */
    @Override
    public SysRelatives selectSysRelativesById(String id)
    {
        return sysRelativesMapper.selectSysRelativesById(id);
    }

    /**
     * 查询家庭成员情况列表
     * 
     * @param sysRelatives 家庭成员情况
     * @return 家庭成员情况
     */
    @Override
    public List<SysRelatives> selectSysRelativesList(SysRelatives sysRelatives)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        int flag = directorRoleUtile.getSTDirectorRole(loginUser);
        List<SysRelatives> relativesList = sysRelativesMapper.selectSysRelativesList(sysRelatives);
        LinkedList<SysRelatives> sysRelativesTemp = new LinkedList<>();
        if(!SecurityUtils.isAdmin(loginUser.getUserId())&&flag==1){
            for (SysRelatives relatives : relativesList) {
                if(relatives.getArcNum().equals(loginUser.getUserId().toString())){
                    sysRelativesTemp.add(relatives);
                }
            }
            return sysRelativesTemp;
        }

        return sysRelativesMapper.selectSysRelativesList(sysRelatives);
    }


    /**
     * 新增家庭成员情况
     * 
     * @param sysRelatives 家庭成员情况
     * @return 结果
     */
    @Override
    public int insertSysRelatives(SysRelatives sysRelatives)
    {

        sysRelatives.setId(UuidUtils.get8UUID());
        sysRelatives.setUserName(SecurityUtils.getUsername());
        sysRelatives.setArcNum(SecurityUtils.getUserId().toString());
        return sysRelativesMapper.insertSysRelatives(sysRelatives);
    }

    /**
     * 修改家庭成员情况
     * 
     * @param sysRelatives 家庭成员情况
     * @return 结果
     */
    @Override
    public int updateSysRelatives(SysRelatives sysRelatives)
    {
        return sysRelativesMapper.updateSysRelatives(sysRelatives);
    }

    /**
     * 批量删除家庭成员情况
     * 
     * @param ids 需要删除的家庭成员情况主键
     * @return 结果
     */
    @Override
    public int deleteSysRelativesByIds(String[] ids)
    {
        return sysRelativesMapper.deleteSysRelativesByIds(ids);
    }

    /**
     * 删除家庭成员情况信息
     * 
     * @param id 家庭成员情况主键
     * @return 结果
     */
    @Override
    public int deleteSysRelativesById(String id)
    {
        return sysRelativesMapper.deleteSysRelativesById(id);
    }
}
